<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .div1 {
      width: 100px;
      height: 100px;
      background-color: red;
    }
    .div2 {
      width: 50px;
      height: 50px;
      background-color: blue;
    }
    .div3 {
      width: 30px;
      height: 30px;
      background-color: green;
    }
  </style>
</head>
<body>
  <div id="app">
    <h1>修饰符</h1>
    <p>1.v-model的修饰符</p>
    <!-- 数字开头，且数据类型是数字 -->
    <label>只能输入数字number:</label>
    <input type="text" v-model.number="val1">
    <p>{{val1}}</p>
    <!-- 中间的空格会保留 -->
    <label>过滤首尾空格trim:</label>
    <input type="text" v-model.trim="val2">
    <p>{{val2}}</p>
    <label>不再实时监听lazy:</label>
    <!-- 将input事件改为chagne事件 -->
    <input type="text" v-model.lazy="val3">
    <p>{{val3}}</p>
    <hr>
    <p>2.事件修饰符</p>
    <p>阻止默认事件:prevent</p>
    <div class="div1" @contextmenu.prevent="show"></div>
    <hr>
    <p>阻止冒泡</p>
    <div class="div1" @click="log1">
      <div class="div2" @click="log2">
        <div class="div3" @click="log3"></div>
      </div>
    </div>
    <hr>
    <p>优先执行：capture，谁有capture就优先执行谁</p>
    <div class="div1" @click.capture="log1">
      <div class="div2" @click.capture="log2">
        <div class="div3" @click="log3"></div>
      </div>
    </div>
    <hr>
    <p>只执行自己的，不包含子元素：self</p>
    <div class="div1" @click.self="log1">
      <div class="div2" @click="log2">
        <div class="div3" @click="log3"></div>
      </div>
    </div>
    <hr>
    <p>只执行一次：once</p>
    <button @click.once="submit">提交</button>
    <hr>
    <p>3.键盘修饰符</p>
    <input type="text" @keyup.enter="add" v-model="msg">
    <button @click="add">添加</button>
    <input type="text" @keyup.up="up">
    <input type="text" @keyup.a="a">
    <input type="text" @keyup.a.ctrl="keycode">
    <hr>
    <p>4.鼠标修饰符</p>
    <p>.right 监听鼠标右键</p>
    <p>.middle 监听鼠标中键</p>
    <p>.left 监听鼠标左键，写他干啥？？？</p>
    <button @click.right="click">鼠标修饰符</button>
  </div>
  <script src="./vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        val1: 0,
        val2: '',
        val3: '',
        msg: ''
      },
      methods: {
        show() {
          console.log(666);
        },
        log1() {
          console.log('div1');
        },
        log2() {
          console.log('div2');
        },
        log3() {
          console.log('div3');
        },
        submit() {
          alert('submit')
        },
        add() {
          console.log(this.msg);
        },
        up() {
          console.log('up');
        },
        a() {
          console.log('a');
        },
        keycode(e) {
          console.log(e);
        },
        click() {
          console.log(666);
        }
      },
    })
  </script>
</body>
</html>